package top.zhangjianyong.tools.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zhangjianyong.tools.entity.stock.StockUser;
import top.zhangjianyong.tools.parm.stock.*;
import top.zhangjianyong.tools.service.api.StockUserService;
import top.zhangjianyong.tools.user.VerifyUser;
import top.zhangjianyong.tools.utils.ApiResponse;

/**
 * @author zhangjianyong
 * @since 2025/3/24 下午2:02
 */
@VerifyUser(user = StockUser.class)
@RestController
@RequestMapping("/stock/user")
public class StockUserController {

    private final StockUserService stockUserService;

    public StockUserController(StockUserService stockUserService) {
        this.stockUserService = stockUserService;
    }

    @VerifyUser(login = false)
    @PostMapping("/login")
    public ApiResponse login(@RequestBody StockUserLoginParam param) throws Exception {
        return stockUserService.login(param);
    }

    @VerifyUser(login = false)
    @PostMapping("/reg")
    public ApiResponse reg(@RequestBody StockUserRegParam param) throws Exception {
        return stockUserService.reg(param);
    }

    @VerifyUser(admin = true, user = StockUser.class)
    @PostMapping("/approve")
    public ApiResponse approve(@RequestBody StockUserApproveParam param) {
        return stockUserService.approve(param);
    }

    @VerifyUser(admin = true, user = StockUser.class)
    @PostMapping("/list")
    public ApiResponse list(@RequestBody StockUserListParam param) {
        return stockUserService.list(param);
    }

    @VerifyUser(admin = true, user = StockUser.class)
    @PostMapping("/update")
    public ApiResponse update(@RequestBody @Validated StockUserUpdateParam param) {
        return stockUserService.update(param);
    }
}
